--[[

LysXP

frame addon is based on two others, xptell and xptogo.

Both of these addons worked reasonably well, but I like having less addons not more, so frame addon handles the functions of both.

]]

local LXP_RepNotification = true;

-- Function: Handle the OnLoad event.
function LXP_OnLoad( frame )
	-- Important programatical events.
	frame:RegisterEvent("PLAYER_ENTERING_WORLD");
	frame:RegisterEvent("PLAYER_LEAVING_WORLD");
end


-- Function: Handle the program events
function LXP_OnEvent(frame, event, ...)
	if (event == "PLAYER_LEAVING_WORLD") then
		-- What events for the whisper messages
		frame:UnregisterEvent("CHAT_MSG_WHISPER");

		-- What events for the XP display routines
		frame:UnregisterEvent("PLAYER_XP_UPDATE");
		frame:UnregisterEvent("PLAYER_LEVEL_UP");
		frame:UnregisterEvent("PLAYER_UPDATE_RESTING");
		frame:UnregisterEvent("UPDATE_EXHAUSTION");

		-- For Pet XP Updates
		frame:UnregisterEvent("UNIT_PET");
		frame:UnregisterEvent("UNIT_PET_EXPERIENCE");
		frame:UnregisterEvent("UNIT_PET_TRAINING_POINTS");
		frame:UnregisterEvent("PET_UI_UPDATE");

		-- What events for the reputation repeat messages
		frame:UnregisterEvent("UPDATE_FACTION");
		frame:UnregisterEvent("FACTION_STANDING_INCREASED");
		frame:UnregisterEvent("FACTION_STANDING_DECREASED");
		return;

	elseif (event == "PLAYER_ENTERING_WORLD") then
		-- What events for the whisper messages
		frame:RegisterEvent("CHAT_MSG_WHISPER");

		-- What events for the XP display routines
		frame:RegisterEvent("PLAYER_XP_UPDATE");
		frame:RegisterEvent("PLAYER_LEVEL_UP");
		frame:RegisterEvent("PLAYER_UPDATE_RESTING");
		frame:RegisterEvent("UPDATE_EXHAUSTION");

		-- For Pet XP Updates
		frame:RegisterEvent("UNIT_PET");
		frame:RegisterEvent("UNIT_PET_EXPERIENCE");
		frame:RegisterEvent("UNIT_PET_TRAINING_POINTS");
		frame:RegisterEvent("PET_UI_UPDATE");

		-- What events for the reputation repeat messages
		frame:RegisterEvent("UPDATE_FACTION");
		frame:RegisterEvent("FACTION_STANDING_INCREASED");
		frame:RegisterEvent("FACTION_STANDING_DECREASED");
		LXP_UpdateXPBar();
		LXP_RepDetails(false);
		return;

	elseif (event == "CHAT_MSG_WHISPER") then
		if (string.find(select(1, ...), "^"..LXP_WHISPER_XP)) then
			LXP_WhisperXP(select(2, ...));
			return;
		elseif (string.find(select(1, ...), "^"..LXP_WHISPER_REP)) then
			LXP_WhisperRep(select(1, ...), select(2, ...));
			return;
		else
			-- Do nothing if the whisper is not one we recognise.
			return;
		end

	elseif ((event == "FACTION_STANDING_INCREASED")
		or (event == "FACTION_STANDING_DECREASED")) then
		DEFAULT_CHAT_FRAME:AddMessage("event:"..event);
		if (select(1, ...) ~= nil) then
			DEFAULT_CHAT_FRAME:AddMessage("arg1:"..select(1, ...));
		end
		if (select(2, ...) ~= nil) then
			DEFAULT_CHAT_FRAME:AddMessage("arg2:"..select(2, ...));
		end
		if (select(3, ...) ~= nil) then
			DEFAULT_CHAT_FRAME:AddMessage("arg3:"..select(3, ...));
		end
		if (select(4, ...) ~= nil) then
			DEFAULT_CHAT_FRAME:AddMessage("arg4:"..select(4, ...));
		end
		if (select(5, ...) ~= nil) then
			DEFAULT_CHAT_FRAME:AddMessage("arg5:"..select(5, ...));
		end
		return;

	elseif (event == "UPDATE_FACTION") then
		if (LXP_RepNotification == false) then
			return;
		end
		LXP_RepDetails(true);
		return;

	-- Player XP Updates
	elseif ((event == "PLAYER_XP_UPDATE")
		or (event == "PLAYER_LEVEL_UP")
		or (event == "PLAYER_UPDATE_RESTING")
		or (event == "UPDATE_EXHAUSTION")
		) then
		LXP_UpdateXPBar();
		return;

	-- Pet XP Updates
	elseif ((event == "UNIT_PET")
		or (event == "UNIT_PET_EXPERIENCE")
		or (event == "UNIT_PET_TRAINING_POINTS")
		or (event == "PET_UI_UPDATE")
		) then
		LXP_UpdatePetXPBar();
		return;

	end
end

-- Function: Which language?
function LXP_ReturnLang()
	if (UnitFactionGroup("player") == "Horde") then
		return "Orcish";
	else
		return "Common";
	end
end
